package com.example.administrator.basedemos.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.administrator.basedemos.bean.FragmentInfo;
import com.example.administrator.basedemos.fragment.OptionalFragment;
import com.example.administrator.basedemos.fragment.RecommendFragment;

import java.util.ArrayList;

/**
 * 创建者     ZCL
 * 创建时间   2018/7/4 10:41
 * 描述	      ${TODO}
 * <p>
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */
public class MarKetVPAdapter extends FragmentPagerAdapter {

    private final ArrayList<FragmentInfo> mList;

    public MarKetVPAdapter(FragmentManager fm) {
        super(fm);
        mList = new ArrayList<>();
        mList.add(new FragmentInfo("自选", OptionalFragment.class));
        mList.add(new FragmentInfo("推荐", RecommendFragment.class));
        mList.add(new FragmentInfo("MCC", RecommendFragment.class));
        mList.add(new FragmentInfo("BTC", RecommendFragment.class));
        mList.add(new FragmentInfo("LTC", RecommendFragment.class));
        mList.add(new FragmentInfo("ETH", RecommendFragment.class));
        mList.add(new FragmentInfo("XRP", RecommendFragment.class));
        mList.add(new FragmentInfo("EOS", RecommendFragment.class));
    }

    @Override
    public Fragment getItem(int position) {
        try {
            return mList.get(position).getaClass().newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mList.get(position).getTitle();
    }
}
